package com.tdkj.service.financial.impl;

import java.sql.Timestamp;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.tdkj.model.financial.BeanTransferRecord;
import com.tdkj.model.user.BeanUser;
import com.tdkj.service.BaseService;
import com.tdkj.service.ServiceException;
import com.tdkj.service.financial.IBeanFimamcialAmountChangeRecordService;
import com.tdkj.service.financial.IBeanTransferRecordService;

@Component
public class BeanTransferRecordServiceImpl extends BaseService implements
		IBeanTransferRecordService {

	private IBeanFimamcialAmountChangeRecordService fimamcialAmountChangeRecordService;
	
	@Resource
	public void setFimamcialAmountChangeRecordService(
			IBeanFimamcialAmountChangeRecordService fimamcialAmountChangeRecordService) {
		this.fimamcialAmountChangeRecordService = fimamcialAmountChangeRecordService;
	}

	@Override
	public void create(Long userId, Long toUserId, Integer money,
			String unit) throws ServiceException {
		BeanUser user = this.getBaseDao().findById(userId, BeanUser.class);
		BeanUser toUser = this.getBaseDao().findById(toUserId, BeanUser.class);
		
		BeanTransferRecord record = new BeanTransferRecord();
		record.setUser(user);
		record.setToUser(toUser);
		record.setMoney(money);
		record.setUnit(unit);
		record.setDateTime(new Timestamp(System.currentTimeMillis()));
		this.getBaseDao().save(record);
		
		fimamcialAmountChangeRecordService.createOut(userId, money, unit, record.getId(), BeanTransferRecord.class, "给别人充值");
		fimamcialAmountChangeRecordService.createOut(toUserId, money, unit, record.getId(), BeanTransferRecord.class, "别人充值");
	}

}
